<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="keywords" content="Hexo Theme Redefine">
    
    <meta name="author" content="xiaoeryu">
    <!-- preconnect -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

    
    <!--- Seo Part-->
    
    <link rel="canonical" href="https://xiaoeeyu.github.io/2023/07/07/ctf006/"/>
    <meta name="robots" content="index,follow">
    <meta name="googlebot" content="index,follow">
    <meta name="revisit-after" content="1 days">
    
    
    
        
        <meta name="description" content="本节主要内容是通过分析题目中的so文件加密，去写出反解脚本计算flag">
<meta property="og:type" content="article">
<meta property="og:title" content="CTF006">
<meta property="og:url" content="https://xiaoeeyu.github.io/2023/07/07/CTF006/index.html">
<meta property="og:site_name" content="xiaoeryu">
<meta property="og:description" content="本节主要内容是通过分析题目中的so文件加密，去写出反解脚本计算flag">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://xiaoeeyu.github.io/2023/07/07/CTF006/image-20230708111943817.png">
<meta property="og:image" content="https://xiaoeeyu.github.io/2023/07/07/CTF006/image-20230708112024572.png">
<meta property="og:image" content="https://xiaoeeyu.github.io/2023/07/07/CTF006/image-20230708123143622.png">
<meta property="og:image" content="https://xiaoeeyu.github.io/2023/07/07/CTF006/image-20230708123203528.png">
<meta property="og:image" content="https://xiaoeeyu.github.io/2023/07/07/CTF006/image-20230708123314917.png">
<meta property="og:image" content="https://xiaoeeyu.github.io/2023/07/07/CTF006/image-20230708123611283.png">
<meta property="og:image" content="https://xiaoeeyu.github.io/2023/07/07/CTF006/image-20230708123621214.png">
<meta property="og:image" content="https://xiaoeeyu.github.io/2023/07/07/CTF006/image-20230708123650927.png">
<meta property="og:image" content="https://xiaoeeyu.github.io/2023/07/07/CTF006/image-20230708123700143.png">
<meta property="og:image" content="https://xiaoeeyu.github.io/2023/07/07/CTF006/image-20230708123740861.png">
<meta property="og:image" content="https://xiaoeeyu.github.io/2023/07/07/CTF006/image-20230708123755894.png">
<meta property="og:image" content="https://xiaoeeyu.github.io/2023/07/07/CTF006/image-20230708123825332.png">
<meta property="og:image" content="https://xiaoeeyu.github.io/2023/07/07/CTF006/image-20230708123945089.png">
<meta property="og:image" content="https://xiaoeeyu.github.io/2023/07/07/CTF006/image-20230708124023310.png">
<meta property="og:image" content="https://xiaoeeyu.github.io/2023/07/07/CTF006/image-20230708124148899.png">
<meta property="article:published_time" content="2023-07-07T14:50:00.000Z">
<meta property="article:modified_time" content="2023-08-25T10:44:07.555Z">
<meta property="article:author" content="xiaoeryu">
<meta property="article:tag" content="Android CTF">
<meta property="article:tag" content="加密解密">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://xiaoeeyu.github.io/2023/07/07/CTF006/image-20230708111943817.png">
    
    
    <!--- Icon Part-->
    <link rel="icon" type="image/png" href="/images/rabete.jpg" sizes="192x192">
    <link rel="apple-touch-icon" sizes="180x180" href="/images/rabete.jpg">
    <meta name="theme-color" content="#A31F34">
    <link rel="shortcut icon" href="/images/rabete.jpg">
    <!--- Page Info-->
    
    <title>
        
            CTF006 | xiaoeryu
        
    </title>

    
<link rel="stylesheet" href="/fonts/Chillax/chillax.css">


    <!--- Inject Part-->
    

    
<link rel="stylesheet" href="/css/style.css">


    
        
<link rel="stylesheet" href="/css/build/tailwind.css">

    

    
<link rel="stylesheet" href="/fonts/GeistMono/geist-mono.css">

    
<link rel="stylesheet" href="/fonts/Geist/geist.css">

    <!--- Font Part-->
    
    
    
    
    
    

    <script id="hexo-configurations">
    window.config = {"hostname":"xiaoeeyu.github.io","root":"/","language":"zh-CN","path":"search.xml"};
    window.theme = {"articles":{"style":{"font_size":"16px","line_height":1.5,"image_border_radius":"14px","image_alignment":"center","image_caption":false,"link_icon":true,"delete_mask":false,"title_alignment":"left","headings_top_spacing":{"h1":"3.2rem","h2":"2.4rem","h3":"1.9rem","h4":"1.6rem","h5":"1.4rem","h6":"1.3rem"}},"word_count":{"enable":true,"count":true,"min2read":true},"author_label":{"enable":true,"auto":false,"list":[]},"code_block":{"copy":true,"style":"mac","highlight_theme":{"light":"github","dark":"vs2015"},"font":{"enable":false,"family":null,"url":null}},"toc":{"enable":true,"max_depth":4,"number":false,"expand":true,"init_open":true},"copyright":{"enable":true,"default":"cc_by_nc_sa"},"lazyload":true,"pangu_js":false,"recommendation":{"enable":false,"title":"推荐阅读","limit":3,"mobile_limit":2,"placeholder":"/images/ball-0101.jpg","skip_dirs":[]}},"colors":{"primary":"#A31F34","secondary":null,"default_mode":"light"},"global":{"fonts":{"chinese":{"enable":false,"family":null,"url":null},"english":{"enable":false,"family":null,"url":null},"title":{"enable":false,"family":null,"url":null}},"content_max_width":"1000px","sidebar_width":"210px","hover":{"shadow":true,"scale":false},"scroll_progress":{"bar":false,"percentage":true},"website_counter":{"url":"https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js","enable":true,"site_pv":true,"site_uv":true,"post_pv":true},"single_page":true,"preloader":{"enable":false,"custom_message":null},"open_graph":true,"google_analytics":{"enable":false,"id":null}},"home_banner":{"enable":true,"style":"fixed","image":{"light":"/images/wallhaven-jxl31y.png","dark":"/images/wallhaven-o5762l.png"},"title":"XIAOERYU","subtitle":{"text":["明心见性，拨云见日","Don't wait, to create"],"hitokoto":{"enable":false,"show_author":false,"api":"https://v1.hitokoto.cn"},"typing_speed":100,"backing_speed":80,"starting_delay":500,"backing_delay":1500,"loop":true,"smart_backspace":true},"text_color":{"light":"#fff","dark":"#d1d1b6"},"text_style":{"title_size":"2.8rem","subtitle_size":"1.5rem","line_height":1.2},"custom_font":{"enable":false,"family":null,"url":null},"social_links":{"enable":true,"style":"default","links":{"github":"https://github.com/xiaoeeyu","instagram":null,"zhihu":null,"twitter":null,"email":"xiaoeryu@163.com"},"qrs":{"weixin":null}}},"plugins":{"feed":{"enable":false},"aplayer":{"enable":false,"type":"fixed","audios":[{"name":null,"artist":null,"url":null,"cover":null,"lrc":null}]},"mermaid":{"enable":false,"version":"9.3.0"}},"version":"2.8.2","navbar":{"auto_hide":false,"color":{"left":"#f78736","right":"#367df7","transparency":35},"width":{"home":"1200px","pages":"1000px"},"links":{"Home":{"path":"/","icon":"fa-regular fa-house"},"Archives":{"path":"/archives","icon":"fa-regular fa-archive"}},"search":{"enable":true,"preload":true}},"page_templates":{"friends_column":2,"tags_style":"blur"},"home":{"sidebar":{"enable":true,"position":"left","first_item":"menu","announcement":null,"show_on_mobile":true,"links":null},"article_date_format":"auto","excerpt_length":200,"categories":{"enable":true,"limit":3},"tags":{"enable":true,"limit":3}},"footerStart":"2022/8/17 11:45:14"};
    window.lang_ago = {"second":"%s 秒前","minute":"%s 分钟前","hour":"%s 小时前","day":"%s 天前","week":"%s 周前","month":"%s 个月前","year":"%s 年前"};
    window.data = {"masonry":false};
  </script>
    
    <!--- Fontawesome Part-->
    
<link rel="stylesheet" href="/fontawesome/fontawesome.min.css">

    
<link rel="stylesheet" href="/fontawesome/brands.min.css">

    
<link rel="stylesheet" href="/fontawesome/solid.min.css">

    
<link rel="stylesheet" href="/fontawesome/regular.min.css">

    
    
    
    
<meta name="generator" content="Hexo 6.3.0">
<style>.github-emoji { position: relative; display: inline-block; width: 1.2em; min-height: 1.2em; overflow: hidden; vertical-align: top; color: transparent; }  .github-emoji > span { position: relative; z-index: 10; }  .github-emoji img, .github-emoji .fancybox { margin: 0 !important; padding: 0 !important; border: none !important; outline: none !important; text-decoration: none !important; user-select: none !important; cursor: auto !important; }  .github-emoji img { height: 1.2em !important; width: 1.2em !important; position: absolute !important; left: 50% !important; top: 50% !important; transform: translate(-50%, -50%) !important; user-select: none !important; cursor: auto !important; } .github-emoji-fallback { color: inherit; } .github-emoji-fallback img { opacity: 0 !important; }</style>
</head>



<body>
	<div class="progress-bar-container">
	

	
	<span class="pjax-progress-bar"></span>
	<!--        <span class="swup-progress-icon">-->
	<!--            <i class="fa-solid fa-circle-notch fa-spin"></i>-->
	<!--        </span>-->
	
</div>

<main class="page-container" id="swup">

	

	<div class="main-content-container flex flex-col justify-between min-h-dvh">
		<div class="main-content-header">
			<header class="navbar-container px-6 md:px-12">
    <div class="navbar-content transition-navbar ">
        <div class="left">
            
                <a class="logo-image h-8 w-8 sm:w-10 sm:h-10 mr-3" href="/">
                    <img src="/images/rabete.jpg" class="w-full h-full rounded-sm">
                </a>
            
            <a class="logo-title" href="/">
                
                xiaoeryu
                
            </a>
        </div>

        <div class="right">
            <!-- PC -->
            <div class="desktop">
                <ul class="navbar-list">
                    
                        
                            

                            <li class="navbar-item">
                                <!-- Menu -->
                                <a class=""
                                   href="/"
                                        >
                                    <i class="fa-regular fa-house fa-fw"></i>
                                    首页
                                    
                                </a>

                                <!-- Submenu -->
                                
                            </li>
                    
                        
                            

                            <li class="navbar-item">
                                <!-- Menu -->
                                <a class=""
                                   href="/archives"
                                        >
                                    <i class="fa-regular fa-archive fa-fw"></i>
                                    归档
                                    
                                </a>

                                <!-- Submenu -->
                                
                            </li>
                    
                    
                        <li class="navbar-item search search-popup-trigger">
                            <i class="fa-solid fa-magnifying-glass"></i>
                        </li>
                    
                </ul>
            </div>
            <!-- Mobile -->
            <div class="mobile">
                
                    <div class="icon-item search search-popup-trigger"><i class="fa-solid fa-magnifying-glass"></i>
                    </div>
                
                <div class="icon-item navbar-bar">
                    <div class="navbar-bar-middle"></div>
                </div>
            </div>
        </div>
    </div>

    <!-- Mobile sheet -->
    <div class="navbar-drawer h-dvh w-full absolute top-0 left-0 bg-background-color flex flex-col justify-between">
        <ul class="drawer-navbar-list flex flex-col px-4 justify-center items-start">
            
                
                    

                    <li class="drawer-navbar-item text-base my-1.5 flex flex-col w-full">
                        
                        <a class="py-1.5 px-2 flex flex-row items-center justify-between gap-1 hover:!text-primary active:!text-primary text-2xl font-semibold group border-b border-border-color hover:border-primary w-full "
                           href="/"
                        >
                            <span>
                                首页
                            </span>
                            
                                <i class="fa-regular fa-house fa-sm fa-fw"></i>
                            
                        </a>
                        

                        
                    </li>
            
                
                    

                    <li class="drawer-navbar-item text-base my-1.5 flex flex-col w-full">
                        
                        <a class="py-1.5 px-2 flex flex-row items-center justify-between gap-1 hover:!text-primary active:!text-primary text-2xl font-semibold group border-b border-border-color hover:border-primary w-full "
                           href="/archives"
                        >
                            <span>
                                归档
                            </span>
                            
                                <i class="fa-regular fa-archive fa-sm fa-fw"></i>
                            
                        </a>
                        

                        
                    </li>
            

            
            
        </ul>

        <div class="statistics flex justify-around my-2.5">
    <a class="item tag-count-item flex flex-col justify-center items-center w-20" href="/tags">
        <div class="number text-2xl sm:text-xl text-second-text-color font-semibold">92</div>
        <div class="label text-third-text-color text-sm">标签</div>
    </a>
    <a class="item tag-count-item flex flex-col justify-center items-center w-20" href="/categories">
        <div class="number text-2xl sm:text-xl text-second-text-color font-semibold">14</div>
        <div class="label text-third-text-color text-sm">分类</div>
    </a>
    <a class="item tag-count-item flex flex-col justify-center items-center w-20" href="/archives">
        <div class="number text-2xl sm:text-xl text-second-text-color font-semibold">112</div>
        <div class="label text-third-text-color text-sm">文章</div>
    </a>
</div>
    </div>

    <div class="window-mask"></div>

</header>


		</div>

		<div class="main-content-body transition-fade-up">
			

			<div class="main-content">
				<div class="post-page-container flex relative justify-between box-border w-full h-full">
	<div class="article-content-container">

		<div class="article-title relative w-full">
			
			<div class="w-full flex items-center pt-6 justify-start">
				<h1 class="article-title-regular text-second-text-color tracking-tight text-4xl md:text-6xl font-semibold px-2 sm:px-6 md:px-8 py-3">CTF006</h1>
			</div>
			
		</div>

		
		<div class="article-header flex flex-row gap-2 items-center px-2 sm:px-6 md:px-8">
			<div class="avatar w-[46px] h-[46px] flex-shrink-0 rounded-medium border border-border-color p-[1px]">
				<img src="/images/rabete.jpg">
			</div>
			<div class="info flex flex-col justify-between">
				<div class="author flex items-center">
					<span class="name text-default-text-color text-lg font-semibold">xiaoeryu</span>
					
					<span class="author-label ml-1.5 text-xs px-2 py-0.5 rounded-small text-third-text-color border border-shadow-color-1">Lv5</span>
					
				</div>
				<div class="meta-info">
					<div class="article-meta-info">
    <span class="article-date article-meta-item">
        <i class="fa-regular fa-pen-fancy"></i>&nbsp;
        <span class="desktop">2023-07-07 22:50</span>
        <span class="mobile">2023-07-07 22:50</span>
        <span class="hover-info">创建</span>
    </span>
    
        <span class="article-date article-meta-item">
            <i class="fa-regular fa-wrench"></i>&nbsp;
            <span class="desktop">2023-08-25 18:44:07</span>
            <span class="mobile">2023-08-25 18:44:07</span>
            <span class="hover-info">更新</span>
        </span>
    

    
        <span class="article-categories article-meta-item">
            <i class="fa-regular fa-folders"></i>&nbsp;
            <ul>
                
                
                    
                        
                        <li>
                            <a href="/categories/Android%E9%80%86%E5%90%91/">Android逆向</a>&nbsp;
                        </li>
                    
                    
                
            </ul>
        </span>
    
    
        <span class="article-tags article-meta-item">
            <i class="fa-regular fa-tags"></i>&nbsp;
            <ul>
                
                    <li>
                        <a href="/tags/Android-CTF/">Android CTF</a>&nbsp;
                    </li>
                
                    <li>
                        | <a href="/tags/%E5%8A%A0%E5%AF%86%E8%A7%A3%E5%AF%86/">加密解密</a>&nbsp;
                    </li>
                
            </ul>
        </span>
    

    
    
    
    
        <span class="article-pv article-meta-item">
            <i class="fa-regular fa-eye"></i>&nbsp;<span id="busuanzi_value_page_pv"></span>
        </span>
    
</div>

				</div>
			</div>
		</div>
		

		


		<div class="article-content markdown-body px-2 sm:px-6 md:px-8 pb-8">
			<p>本节主要内容是通过分析题目中的so文件加密，去写出反解脚本计算flag</p>
<span id="more"></span>



<img lazyload="" src="/images/loading.svg" data-src="/2023/07/07/CTF006/image-20230708111943817.png" class="" title="image-20230708111943817">

<h3 id="1-用jadx查看入口点"><a href="#1-用jadx查看入口点" class="headerlink" title="1. 用jadx查看入口点"></a>1. 用jadx查看入口点</h3><p>在<em>AndroidManifest.xml</em>里面找到入口函数</p>
<!-- more -->

<img lazyload="" src="/images/loading.svg" data-src="/2023/07/07/CTF006/image-20230708112024572.png" class="" title="image-20230708112024572">

<h4 id="1-1-看这段代码我们需要关注两个方法："><a href="#1-1-看这段代码我们需要关注两个方法：" class="headerlink" title="1.1. 看这段代码我们需要关注两个方法："></a>1.1. 看这段代码我们需要关注两个方法：</h4><pre><code>  1. getSecret()是一个native层的函数，这个函数对编辑框的内容进行了一定的处理之后返回了ans
  2. check()方法校验，通过校验才能得到正确的Flag
</code></pre>
<p>先分析下chek()是怎么实现的，等下再去看native层。</p>
<h3 id="2-查看check-方法"><a href="#2-查看check-方法" class="headerlink" title="2. 查看check()方法"></a>2. 查看check()方法</h3><img lazyload="" src="/images/loading.svg" data-src="/2023/07/07/CTF006/image-20230708123143622.png" class="" title="image-20230708123143622">

<p>这段代码的主要作用是从数据库中取出<strong>secret</strong>值（用hello的MD5值作为name对应的secret值）与我们输入的值（经过getSecret()方法处理）进行比较相等就返回true。</p>
<img lazyload="" src="/images/loading.svg" data-src="/2023/07/07/CTF006/image-20230708123203528.png" class="" title="image-20230708123203528">

<p>分析完check()方法之后，现在我们可知：</p>
<ul>
<li>输入编辑框的值经过getSecret()的运算之后 = ‘kEvKc|roAkNADgGExUeq’就可以通过校验</li>
</ul>
<p>那接下来我们去分析一下getSecret()这个方法。</p>
<h3 id="3-分析getSecret"><a href="#3-分析getSecret" class="headerlink" title="3. 分析getSecret()"></a>3. 分析getSecret()</h3><h4 id="3-1-用ida打开so文件之后，通过命名惯例用java定位到函数位置，再按F5修改以下参数类型方便分析"><a href="#3-1-用ida打开so文件之后，通过命名惯例用java定位到函数位置，再按F5修改以下参数类型方便分析" class="headerlink" title="3.1. 用ida打开so文件之后，通过命名惯例用java定位到函数位置，再按F5修改以下参数类型方便分析"></a>3.1. 用ida打开so文件之后，通过命名惯例用java定位到函数位置，再按F5修改以下参数类型方便分析</h4><img lazyload="" src="/images/loading.svg" data-src="/2023/07/07/CTF006/image-20230708123314917.png" class="" title="image-20230708123314917">

<h4 id="3-2-先初步分析这段代码来猜测里面的逻辑（因为不知道参数的内容，所以猜测不一定正确）我们依旧可以知道几点"><a href="#3-2-先初步分析这段代码来猜测里面的逻辑（因为不知道参数的内容，所以猜测不一定正确）我们依旧可以知道几点" class="headerlink" title="3.2. 先初步分析这段代码来猜测里面的逻辑（因为不知道参数的内容，所以猜测不一定正确）我们依旧可以知道几点"></a>3.2. 先初步分析这段代码来猜测里面的逻辑（因为不知道参数的内容，所以猜测不一定正确）我们依旧可以知道几点</h4><pre><code>  1. 代码通过接收我们输入的字符串，将其和内置的base_string进行一些运算得到一个新的字符串，最后将新的字符串返回
  2. 因为最后返回的新字符串是动态生成的，所以我们无法通过简单的hook去获取到正确的flag
  3. 这样子的话我们只能尝试一下看，能不能通过分析它的算法和入参写出它的反解算法
  4. 我们要详细分析算法写反解脚本的话，需要通过动态调试的方法来确定它的入参和返回值，另外静态反编译出来的伪代码可能也不准确不能支持我们去精确的写出反解算法
</code></pre>
<h3 id="4-用ida动态附加调试：attach过程略过"><a href="#4-用ida动态附加调试：attach过程略过" class="headerlink" title="4. 用ida动态附加调试：attach过程略过"></a>4. 用ida动态附加调试：attach过程略过</h3><h4 id="4-1-attach程序之后，找到我们的getSecret-方法下断点段下来"><a href="#4-1-attach程序之后，找到我们的getSecret-方法下断点段下来" class="headerlink" title="4.1. attach程序之后，找到我们的getSecret()方法下断点段下来"></a>4.1. attach程序之后，找到我们的getSecret()方法下断点段下来</h4><img lazyload="" src="/images/loading.svg" data-src="/2023/07/07/CTF006/image-20230708123611283.png" class="" title="image-20230708123611283">

<img lazyload="" src="/images/loading.svg" data-src="/2023/07/07/CTF006/image-20230708123621214.png" class="" title="image-20230708123621214">

<p>在函数开始的地方下断点，在手机上点击_<strong>TRY IT!</strong>_按钮之后我们可以中断在这里，这时候我们可以看到它的<strong>base_string</strong>字符串<br>_F8_继续往下跟，到获取dest[]的地方</p>
<img lazyload="" src="/images/loading.svg" data-src="/2023/07/07/CTF006/image-20230708123650927.png" class="" title="image-20230708123650927">

<img lazyload="" src="/images/loading.svg" data-src="/2023/07/07/CTF006/image-20230708123700143.png" class="" title="image-20230708123700143">

<p>分析后可以发现数组的内容是从0~0x44的dw数组。</p>
<h4 id="4-2-接下来开始分析for循环"><a href="#4-2-接下来开始分析for循环" class="headerlink" title="4.2. 接下来开始分析for循环"></a>4.2. 接下来开始分析for循环</h4><p><strong>第一个for循环</strong></p>
<img lazyload="" src="/images/loading.svg" data-src="/2023/07/07/CTF006/image-20230708123740861.png" class="" title="image-20230708123740861">

<ul>
<li><p>循环的次数根据组的长度获得</p>
</li>
<li><p>循环取出dest[i]中的值 + <strong>0x10</strong>，然后再写回去</p>
<p><strong>第二个嵌套for循环</strong></p>
</li>
</ul>
<img lazyload="" src="/images/loading.svg" data-src="/2023/07/07/CTF006/image-20230708123755894.png" class="" title="image-20230708123755894">

<ul>
<li>外层循环的次数是我们输入的字符串的长度</li>
<li>内存循环的次数是base_string字符串的长度</li>
<li>这个嵌套循环是将我们输入的字符逐个和base_string中的字符对比，相等的话就跳出本轮内层循环</li>
</ul>
<img lazyload="" src="/images/loading.svg" data-src="/2023/07/07/CTF006/image-20230708123825332.png" class="" title="image-20230708123825332">

<p>用循环次数去dest[]中取出对应的值-&gt;再用这个取出的值去base_string中取出对应下标的字符-&gt;然后用这个字符替换掉我们输入的inputStr[外层循环]的字符</p>
<p><strong>最后一个循环</strong></p>
<img lazyload="" src="/images/loading.svg" data-src="/2023/07/07/CTF006/image-20230708123945089.png" class="" title="image-20230708123945089">

<ul>
<li>最后一个循环时将我们前面循环生成的新字符串再次循环进行<strong>^</strong>操作，然后放回原位、</li>
</ul>
<h3 id="5-然后这个加密我们就全部分析完成了，修改一下我们前面猜错的伪代码注释"><a href="#5-然后这个加密我们就全部分析完成了，修改一下我们前面猜错的伪代码注释" class="headerlink" title="5. 然后这个加密我们就全部分析完成了，修改一下我们前面猜错的伪代码注释"></a>5. 然后这个加密我们就全部分析完成了，修改一下我们前面猜错的伪代码注释</h3><img lazyload="" src="/images/loading.svg" data-src="/2023/07/07/CTF006/image-20230708124023310.png" class="" title="image-20230708124023310">

<h3 id="算法分析完成"><a href="#算法分析完成" class="headerlink" title="算法分析完成"></a>算法分析完成</h3><p>接下来我们就可以写这个算法的反解脚本了，写反解脚本可以从最后一个循环往前推过去</p>
<p><strong>结果字符串循环对字符进行与运算，然后再取模128确保结果不大于ASCII码的最大值-&gt;然后将计算完成的字符逐个在base_string里面找到字符对应的索引值(即dest[k]的值)-&gt;如果这个索引值小于16(dest[]中的最小值0x10)表示它对应的索引值在base_string的前16位-&gt;就把下标值加上base_string的长度-&gt;最后打印字符的时候还要把索引值([dest[i]])减去0x10</strong></p>
<pre><code class="python">static_str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!{|}~'
now = 'kEvKc|roAkNADgGExUeq'
for i, each in enumerate(now):
    tmp = chr((ord(each)^i)%128)
    index = static_str.find(tmp)
    if index &lt; 16:
        index = index + len(static_str) # 如果index &lt; 16，给index加上字符集长度实现循环查找
    print(static_str[index-16], end='')
</code></pre>
<img lazyload="" src="/images/loading.svg" data-src="/2023/07/07/CTF006/image-20230708124148899.png" class="" title="image-20230708124148899">

<p><strong>over~</strong></p>

		</div>

		
		<div class="post-copyright-info w-full my-8 px-2 sm:px-6 md:px-8">
			<div class="article-copyright-info-container">
    <ul>
        <li><strong>标题:</strong> CTF006</li>
        <li><strong>作者:</strong> xiaoeryu</li>
        <li><strong>创建于
                :</strong> 2023-07-07 22:50:00</li>
        
            <li>
                <strong>更新于
                    :</strong> 2023-08-25 18:44:07
            </li>
        
        <li>
            <strong>链接:</strong> https://github.com/xiaoeryu/2023/07/07/CTF006/
        </li>
        <li>
            <strong>
                版权声明:
            </strong>
            

            
                本文章采用 <a class="license" target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0">CC BY-NC-SA 4.0</a> 进行许可。
            
        </li>
    </ul>
</div>

		</div>
		

		
		<ul class="post-tags-box text-lg mt-1.5 flex-wrap justify-center flex md:hidden">
			
			<li class="tag-item mx-0.5">
				<a href="/tags/Android-CTF/">#Android CTF</a>&nbsp;
			</li>
			
			<li class="tag-item mx-0.5">
				<a href="/tags/%E5%8A%A0%E5%AF%86%E8%A7%A3%E5%AF%86/">#加密解密</a>&nbsp;
			</li>
			
		</ul>
		

		

		
		<div class="article-nav my-8 flex justify-between items-center px-2 sm:px-6 md:px-8">
			
			<div class="article-prev border-border-color shadow-redefine-flat shadow-shadow-color-2 rounded-medium px-4 py-2 hover:shadow-redefine-flat-hover hover:shadow-shadow-color-2">
				<a class="prev" rel="prev" href="/2023/07/08/CTF005/">
					<span class="left arrow-icon flex justify-center items-center">
						<i class="fa-solid fa-chevron-left"></i>
					</span>
					<span class="title flex justify-center items-center">
						<span class="post-nav-title-item">CTF005</span>
						<span class="post-nav-item">上一篇</span>
					</span>
				</a>
			</div>
			
			
			<div class="article-next border-border-color shadow-redefine-flat shadow-shadow-color-2 rounded-medium px-4 py-2 hover:shadow-redefine-flat-hover hover:shadow-shadow-color-2">
				<a class="next" rel="next" href="/2022/12/11/32-%E5%B9%B3%E5%9D%A6%E6%A8%A1%E5%9E%8B/">
					<span class="title flex justify-center items-center">
						<span class="post-nav-title-item">平坦模型</span>
						<span class="post-nav-item">下一篇</span>
					</span>
					<span class="right arrow-icon flex justify-center items-center">
						<i class="fa-solid fa-chevron-right"></i>
					</span>
				</a>
			</div>
			
		</div>
		


		
		<div class="comment-container px-2 sm:px-6 md:px-8 pb-8">
			<div class="comments-container mt-10 w-full ">
    <div id="comment-anchor" class="w-full h-2.5"></div>
    <div class="comment-area-title w-full my-1.5 md:my-2.5 text-xl md:text-3xl font-bold">
        评论
    </div>
    

        
            


        
    
</div>

		</div>
		
	</div>

	
	<div class="toc-content-container">
		<div class="post-toc-wrap">
	<div class="post-toc">
		<div class="toc-title">目录</div>
		<div class="page-title">CTF006</div>
		<ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-%E7%94%A8jadx%E6%9F%A5%E7%9C%8B%E5%85%A5%E5%8F%A3%E7%82%B9"><span class="nav-text">1. 用jadx查看入口点</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-1-%E7%9C%8B%E8%BF%99%E6%AE%B5%E4%BB%A3%E7%A0%81%E6%88%91%E4%BB%AC%E9%9C%80%E8%A6%81%E5%85%B3%E6%B3%A8%E4%B8%A4%E4%B8%AA%E6%96%B9%E6%B3%95%EF%BC%9A"><span class="nav-text">1.1. 看这段代码我们需要关注两个方法：</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-%E6%9F%A5%E7%9C%8Bcheck-%E6%96%B9%E6%B3%95"><span class="nav-text">2. 查看check()方法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-%E5%88%86%E6%9E%90getSecret"><span class="nav-text">3. 分析getSecret()</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#3-1-%E7%94%A8ida%E6%89%93%E5%BC%80so%E6%96%87%E4%BB%B6%E4%B9%8B%E5%90%8E%EF%BC%8C%E9%80%9A%E8%BF%87%E5%91%BD%E5%90%8D%E6%83%AF%E4%BE%8B%E7%94%A8java%E5%AE%9A%E4%BD%8D%E5%88%B0%E5%87%BD%E6%95%B0%E4%BD%8D%E7%BD%AE%EF%BC%8C%E5%86%8D%E6%8C%89F5%E4%BF%AE%E6%94%B9%E4%BB%A5%E4%B8%8B%E5%8F%82%E6%95%B0%E7%B1%BB%E5%9E%8B%E6%96%B9%E4%BE%BF%E5%88%86%E6%9E%90"><span class="nav-text">3.1. 用ida打开so文件之后，通过命名惯例用java定位到函数位置，再按F5修改以下参数类型方便分析</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-2-%E5%85%88%E5%88%9D%E6%AD%A5%E5%88%86%E6%9E%90%E8%BF%99%E6%AE%B5%E4%BB%A3%E7%A0%81%E6%9D%A5%E7%8C%9C%E6%B5%8B%E9%87%8C%E9%9D%A2%E7%9A%84%E9%80%BB%E8%BE%91%EF%BC%88%E5%9B%A0%E4%B8%BA%E4%B8%8D%E7%9F%A5%E9%81%93%E5%8F%82%E6%95%B0%E7%9A%84%E5%86%85%E5%AE%B9%EF%BC%8C%E6%89%80%E4%BB%A5%E7%8C%9C%E6%B5%8B%E4%B8%8D%E4%B8%80%E5%AE%9A%E6%AD%A3%E7%A1%AE%EF%BC%89%E6%88%91%E4%BB%AC%E4%BE%9D%E6%97%A7%E5%8F%AF%E4%BB%A5%E7%9F%A5%E9%81%93%E5%87%A0%E7%82%B9"><span class="nav-text">3.2. 先初步分析这段代码来猜测里面的逻辑（因为不知道参数的内容，所以猜测不一定正确）我们依旧可以知道几点</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-%E7%94%A8ida%E5%8A%A8%E6%80%81%E9%99%84%E5%8A%A0%E8%B0%83%E8%AF%95%EF%BC%9Aattach%E8%BF%87%E7%A8%8B%E7%95%A5%E8%BF%87"><span class="nav-text">4. 用ida动态附加调试：attach过程略过</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#4-1-attach%E7%A8%8B%E5%BA%8F%E4%B9%8B%E5%90%8E%EF%BC%8C%E6%89%BE%E5%88%B0%E6%88%91%E4%BB%AC%E7%9A%84getSecret-%E6%96%B9%E6%B3%95%E4%B8%8B%E6%96%AD%E7%82%B9%E6%AE%B5%E4%B8%8B%E6%9D%A5"><span class="nav-text">4.1. attach程序之后，找到我们的getSecret()方法下断点段下来</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-2-%E6%8E%A5%E4%B8%8B%E6%9D%A5%E5%BC%80%E5%A7%8B%E5%88%86%E6%9E%90for%E5%BE%AA%E7%8E%AF"><span class="nav-text">4.2. 接下来开始分析for循环</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-%E7%84%B6%E5%90%8E%E8%BF%99%E4%B8%AA%E5%8A%A0%E5%AF%86%E6%88%91%E4%BB%AC%E5%B0%B1%E5%85%A8%E9%83%A8%E5%88%86%E6%9E%90%E5%AE%8C%E6%88%90%E4%BA%86%EF%BC%8C%E4%BF%AE%E6%94%B9%E4%B8%80%E4%B8%8B%E6%88%91%E4%BB%AC%E5%89%8D%E9%9D%A2%E7%8C%9C%E9%94%99%E7%9A%84%E4%BC%AA%E4%BB%A3%E7%A0%81%E6%B3%A8%E9%87%8A"><span class="nav-text">5. 然后这个加密我们就全部分析完成了，修改一下我们前面猜错的伪代码注释</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%AE%97%E6%B3%95%E5%88%86%E6%9E%90%E5%AE%8C%E6%88%90"><span class="nav-text">算法分析完成</span></a></li></ol>

	</div>
</div>
	</div>
	
</div>
			</div>

			
		</div>

		<div class="main-content-footer">
			<footer class="footer mt-5 py-5 h-auto text-base text-third-text-color relative border-t-2 border-t-border-color">
    <div class="info-container py-3 text-center">
        
        <div class="text-center">
            &copy;
            
              <span>2022</span>
              -
            
            2025&nbsp;&nbsp;<i class="fa-solid fa-heart fa-beat" style="--fa-animation-duration: 0.5s; color: #f54545"></i>&nbsp;&nbsp;<a href="/">xiaoeryu</a>
            
                
                <p class="post-count space-x-0.5">
                    <span>
                        共撰写了 112 篇文章
                    </span>
                    
                </p>
            
        </div>
        
            <script data-swup-reload-script src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
            <div class="relative text-center lg:absolute lg:right-[20px] lg:top-1/2 lg:-translate-y-1/2 lg:text-right">
                
                    <span id="busuanzi_container_site_uv" class="lg:!block">
                        <span class="text-sm">访问人数</span>
                        <span id="busuanzi_value_site_uv"></span>
                    </span>
                
                
                    <span id="busuanzi_container_site_pv" class="lg:!block">
                        <span class="text-sm">总访问量</span>
                        <span id="busuanzi_value_site_pv"></span>
                    </span>
                
            </div>
        
        <div class="relative text-center lg:absolute lg:left-[20px] lg:top-1/2 lg:-translate-y-1/2 lg:text-left">
            <span class="lg:block text-sm">由 <?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg class="relative top-[2px] inline-block align-baseline" version="1.1" id="圖層_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1rem" height="1rem" viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve"><path fill="#0E83CD" d="M256.4,25.8l-200,115.5L56,371.5l199.6,114.7l200-115.5l0.4-230.2L256.4,25.8z M349,354.6l-18.4,10.7l-18.6-11V275H200v79.6l-18.4,10.7l-18.6-11v-197l18.5-10.6l18.5,10.8V237h112v-79.6l18.5-10.6l18.5,10.8V354.6z"/></svg><a target="_blank" class="text-base" href="https://hexo.io">Hexo</a> 驱动</span>
            <span class="text-sm lg:block">主题&nbsp;<a class="text-base" target="_blank" href="https://github.com/EvanNotFound/hexo-theme-redefine">Redefine v2.8.2</a></span>
        </div>
        
        
            <div>
                博客已运行 <span class="odometer" id="runtime_days" ></span> 天 <span class="odometer" id="runtime_hours"></span> 小时 <span class="odometer" id="runtime_minutes"></span> 分钟 <span class="odometer" id="runtime_seconds"></span> 秒
            </div>
        
        
            <script data-swup-reload-script>
                try {
                    function odometer_init() {
                    const elements = document.querySelectorAll('.odometer');
                    elements.forEach(el => {
                        new Odometer({
                            el,
                            format: '( ddd).dd',
                            duration: 200
                        });
                    });
                    }
                    odometer_init();
                } catch (error) {}
            </script>
        
        
        
    </div>  
</footer>
		</div>
	</div>

	
	<div class="post-tools">
		<div class="post-tools-container">
	<ul class="article-tools-list">
		<!-- TOC aside toggle -->
		
		<li class="right-bottom-tools page-aside-toggle">
			<i class="fa-regular fa-outdent"></i>
		</li>
		

		<!-- go comment -->
		
		<li class="go-comment">
			<i class="fa-regular fa-comments"></i>
		</li>
		
	</ul>
</div>
	</div>
	

	<div class="right-side-tools-container">
		<div class="side-tools-container">
	<ul class="hidden-tools-list">
		<li class="right-bottom-tools tool-font-adjust-plus flex justify-center items-center">
			<i class="fa-regular fa-magnifying-glass-plus"></i>
		</li>

		<li class="right-bottom-tools tool-font-adjust-minus flex justify-center items-center">
			<i class="fa-regular fa-magnifying-glass-minus"></i>
		</li>

		<li class="right-bottom-tools tool-dark-light-toggle flex justify-center items-center">
			<i class="fa-regular fa-moon"></i>
		</li>

		<!-- rss -->
		

		

		<li class="right-bottom-tools tool-scroll-to-bottom flex justify-center items-center">
			<i class="fa-regular fa-arrow-down"></i>
		</li>
	</ul>

	<ul class="visible-tools-list">
		<li class="right-bottom-tools toggle-tools-list flex justify-center items-center">
			<i class="fa-regular fa-cog fa-spin"></i>
		</li>
		
		<li class="right-bottom-tools tool-scroll-to-top flex justify-center items-center">
			<i class="arrow-up fas fa-arrow-up"></i>
			<span class="percent"></span>
		</li>
		
		
	</ul>
</div>
	</div>

	<div class="image-viewer-container">
	<img src="">
</div>

	
	<div class="search-pop-overlay">
	<div class="popup search-popup">
		<div class="search-header">
			<span class="search-input-field-pre">
				<i class="fa-solid fa-keyboard"></i>
			</span>
			<div class="search-input-container">
				<input autocomplete="off" autocorrect="off" autocapitalize="off" placeholder="站内搜索您需要的内容..." spellcheck="false" type="search" class="search-input">
			</div>
			<span class="popup-btn-close">
				<i class="fa-solid fa-times"></i>
			</span>
		</div>
		<div id="search-result">
			<div id="no-result">
				<i class="fa-solid fa-spinner fa-spin-pulse fa-5x fa-fw"></i>
			</div>
		</div>
	</div>
</div>
	

</main>



<script src="/js/build/libs/Swup.min.js"></script>

<script src="/js/build/libs/SwupSlideTheme.min.js"></script>

<script src="/js/build/libs/SwupScriptsPlugin.min.js"></script>

<script src="/js/build/libs/SwupProgressPlugin.min.js"></script>

<script src="/js/build/libs/SwupScrollPlugin.min.js"></script>

<script src="/js/build/libs/SwupPreloadPlugin.min.js"></script>

<script>
    const swup = new Swup({
        plugins: [
            new SwupScriptsPlugin({
                optin: true,
            }),
            new SwupProgressPlugin(),
            new SwupScrollPlugin({
                offset: 80,
            }),
            new SwupSlideTheme({
                mainElement: ".main-content-body",
            }),
            new SwupPreloadPlugin(),
        ],
        containers: ["#swup"],
    });
</script>




	
<script src="/js/build/tools/imageViewer.js" type="module"></script>

<script src="/js/build/utils.js" type="module"></script>

<script src="/js/build/main.js" type="module"></script>

<script src="/js/build/layouts/navbarShrink.js" type="module"></script>

<script src="/js/build/tools/scrollTopBottom.js" type="module"></script>

<script src="/js/build/tools/lightDarkSwitch.js" type="module"></script>

<script src="/js/build/layouts/categoryList.js" type="module"></script>



    
<script src="/js/build/tools/localSearch.js" type="module"></script>




    
<script src="/js/build/tools/codeBlock.js" type="module"></script>




    
<script src="/js/build/layouts/lazyload.js" type="module"></script>




    
<script src="/js/build/tools/runtime.js"></script>

    
<script src="/js/build/libs/odometer.min.js"></script>

    
<link rel="stylesheet" href="/assets/odometer-theme-minimal.css">




  
<script src="/js/build/libs/Typed.min.js"></script>

  
<script src="/js/build/plugins/typed.js" type="module"></script>








    
<script src="/js/build/libs/anime.min.js"></script>





    
<script src="/js/build/tools/tocToggle.js" type="module" data-swup-reload-script=""></script>

<script src="/js/build/layouts/toc.js" type="module" data-swup-reload-script=""></script>

<script src="/js/build/plugins/tabs.js" type="module" data-swup-reload-script=""></script>




<script src="/js/build/libs/moment-with-locales.min.js" data-swup-reload-script=""></script>


<script src="/js/build/layouts/essays.js" type="module" data-swup-reload-script=""></script>





	
</body>

</html>